import { Component, OnInit, AfterContentInit, Input } from '@angular/core';
import { filter } from 'rxjs/operators';
import { NavigationEnd, Router } from '@angular/router';
import { EventService } from 'src/app/service/event.service';
import { NavController } from '@ionic/angular';
import { ConfigService } from 'src/app/service/config.service';

@Component({
  selector: 'app-tab-self',
  templateUrl: './tab-self.component.html',
  styleUrls: ['./tab-self.component.scss'],
})
export class TabSelfComponent implements OnInit {
  public flag: string = "";
  @Input() name:any;
  constructor(private router: Router, private eventS: EventService,private navCtrl:NavController) {
    this.initEvent();
    this.navEvents();
    
  }

  ngOnInit() {
      if(this.name==1 || this.name=='1'){
          this.name="大厅";
      }else{
          this.name="首页";
      }
  }

  initEvent() {
    let that = this;
    this.eventS.subscribe("getRouterName", function (name) {
      that.flag=name;
    }, true);
  }

  selectFun(mark,name) {
      this.eventS.publish("self-tab",mark);
      if(ConfigService.is3rd && name=="home"){
        this.navCtrl.navigateRoot("/tabs/index3rd");
      }else{
        this.navCtrl.navigateRoot("/tabs/"+name);
      }
      
  }
  private navEvents() {
    let that = this;
    this.router.events.pipe(filter(e => e instanceof NavigationEnd)).subscribe((e: any) => {
      if (e.urlAfterRedirects != '/tabs/my' && e.urlAfterRedirects != '/tabs/home' && e.urlAfterRedirects != '/tabs/index3rd' && e.urlAfterRedirects != '/tabs/lottery' && e.urlAfterRedirects != '/tabs/report' && e.urlAfterRedirects != '/tabs/recharge') {
         that.eventS.publish("getRouterName","home");
      }
    });
  }

}
